<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-修改密码</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_user.css">
	<link rel="stylesheet" href="/resource/css/gl_showBo.css">

	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_showBo.js"></script>
	<script src="/resource/js/gl_index.js"></script>
	<script>
		$(function(){
			$('input.form-control').blur(function(){

				var user_id = $('#user_id').val();
				var old_password = $('#old_password').val();
				var new_password = $('#new_password').val();
	            var new_password1 = $('#new_password1').val();

				if (!$(this).val()) {
					$(this).siblings('span').html('不能为空').show();
				}else{
					if ($(this).attr('id') == 'old_password') {
						$.ajax({
							url : '/user_password_select',
							type : "POST",
							data : {user_id:user_id,password:old_password},
							dataType : "json",
							cache:"false",
							timeout:30000,
							success : function(json) {
		                        console.log(json);
								if(json.code == 0){
		                            $('#old_password').siblings('span').show().html('旧密码输入错误');
								}else{
									$('#old_password').siblings('span').hide();
								};
							}
						});
					}
					if ($(this).attr('id') == 'new_password1') {
//						console.log(new_password);
//						console.log(new_password1);
			            if(new_password!=new_password1){
			                $(this).siblings('span').show().html('两次输入密码不一致');
			            }else{
							$(this).siblings('span').hide();
						};
					};
//					$(this).siblings('span').hide();
				};
			});

			$('.btn-login').click(function(){
				var user_id = $('#user_id').val();
				var old_password = $('#old_password').val();
				var new_password = $('#new_password1').val();
				if(old_password==''){
					$('#old_password').siblings('span').show().html('不能为空');
					return false;
				}else{
					$('#old_password').siblings('span').hide();
				}
				if(new_password==''){
					$('#new_password').siblings('span').show().html('不能为空');
					return false;
				}else{
					$('#new_password').siblings('span').hide();
				}
				if(new_password1==''){
					$('#new_password1').siblings('span').show().html('不能为空');
					return false;
				}else{
					$('#new_password1').siblings('span').hide();
				}
				$('.form-group span').hide();
				$.ajax({
					url : '/user_password_update',
					type : "POST",
					data : {user_id:user_id,old_password:old_password,new_password:new_password},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						console.log(json);
						if(json.code == 1){

							Showbo.Msg.amend('<img src="/resource/img/reg_success.png" style="margin-top: 30px"><div style="margin-bottom: 30px;">重置成功</div>',function(btn){
								if (btn == 'yes') {
									window.location.href = '/logout';
								}else{
									return false;
								};
							},'重新登录');

						}
					}
				});

			});

		});
	</script>
</head>
<body>
<div class="head">
	@include('common.user_head')
</div>
<div class="user-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<div>我的钢链网
				<a href="/">返回首页</a>
			</div>
		</div>
	</div>
</div>	
<div class="user main">
	@include('common.user_menu')
	<div class="user-cont">
		<div class="password">
			<div class="title">修改密码</div>
			<div class="form">

					<div class="form-group">
		                <label for="">旧密码</label>
		                <input type="password" id="old_password" class="form-control" placeholder="请输入旧密码">
		                <span>不能为空</span>
		            </div>
		            <div class="form-group">
		                <label for="">新密码</label>
		                <input type="password" id="new_password" class="form-control" placeholder="请输入新密码">
		                <span>不能为空</span>
		            </div>
		            <div class="form-group">
		                <label for="">再次输入</label>
		                <input type="password" id="new_password1" class="form-control" placeholder="请再次输入新密码">
		                <span>两次密码输入不一致</span>
		            </div>
					<input type="hidden" id="user_id" value={{$user_id}}>
		            <button type="button" class="btn-login">提交</button>

			</div>
		</div>
	</div>
</div>
@include('common.shop_foot')
</body>
</html>